//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.farm.wcp.controller;

import com.farm.core.auth.domain.LoginUser;
import com.farm.core.page.ViewMode;
import com.farm.core.sql.query.DataQuery.CACHE_UNIT;
import com.farm.core.sql.result.DataResult;
import com.farm.doc.domain.FarmDoctype;
import com.farm.doc.domain.ex.TypeBrief;
import com.farm.doc.server.FarmDocManagerInter;
import com.farm.doc.server.FarmDocOperateRightInter;
import com.farm.doc.server.FarmDocRunInfoInter;
import com.farm.doc.server.FarmDocTypeInter;
import com.farm.doc.server.FarmDocgroupManagerInter;
import com.farm.doc.server.FarmDocmessageManagerInter;
import com.farm.doc.server.FarmFileManagerInter;
import com.farm.parameter.FarmParameterService;
import com.farm.util.cache.FarmSuperCache;
import com.farm.util.cache.FarmSuperCatchFunc;
import com.farm.wcp.know.service.KnowServiceInter;
import com.farm.wcp.util.ThemesUtil;
import com.farm.web.WebUtils;

import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@RequestMapping({ "/webtype" })
@Controller
public class DocTypeController extends WebUtils {
	@Resource
	private FarmDocgroupManagerInter farmDocgroupManagerImpl;
	@Resource
	private FarmFileManagerInter farmFileManagerImpl;
	@Resource
	private FarmDocManagerInter farmDocManagerImpl;
	@Resource
	private FarmDocRunInfoInter farmDocRunInfoImpl;
	@Resource
	private KnowServiceInter KnowServiceImpl;
	@Resource
	private FarmDocmessageManagerInter farmDocmessageManagerImpl;
	@Resource
	private FarmDocOperateRightInter farmDocOperateRightImpl;
	@Resource
	private FarmDocTypeInter farmDocTypeManagerImpl;

	public DocTypeController() {
	}

	@RequestMapping(value = { "/view{typeid}/Pub{pagesize}" }, method = { RequestMethod.GET })
	public ModelAndView types(@PathVariable("typeid") String typeid, HttpSession session, HttpServletRequest request,
			@PathVariable("pagesize") Integer pagenum) throws Exception {
		ViewMode mode = ViewMode.getInstance();
		if (typeid != null && !typeid.isEmpty()) {
			mode.putAttr("type", this.farmDocTypeManagerImpl.getType(typeid));
			mode.putAttr("typepop", this.farmDocTypeManagerImpl.getTypePops(typeid));
		} else {
			typeid = "NONE";
		}

		if (pagenum == null) {
			pagenum = Integer.valueOf(1);
		}

		LoginUser user = this.getCurrentUser(session);
		mode.putAttr("typeid", typeid);
		List<FarmDoctype> typepath = this.farmDocTypeManagerImpl.getTypeAllParent(typeid);
		List<TypeBrief> typesons = this.farmDocTypeManagerImpl.getTypeInfos(this.getCurrentUser(session), typeid);
		DataResult docs = this.farmDocTypeManagerImpl.getTypeDocs(user, typeid, 10, pagenum.intValue());
		return mode.putAttr("typesons", typesons).putAttr("typepath", typepath).putAttr("docs", docs)
				.returnModelAndView(ThemesUtil.getThemePath() + "/type/type");
	}

	@RequestMapping({ "/PubLoadRType" })
	@ResponseBody
	public Map<String, Object> typeRead(String typeid, final HttpSession session) {
		try {
			String userid = this.getCurrentUser(session) == null ? "" : this.getCurrentUser(session).getId();
			List<TypeBrief> types = (List) FarmSuperCache.getValue("typeRs" + userid, Integer
					.valueOf(FarmParameterService.getInstance().getParameter("config.wcp.cache.alltypes")).intValue(),
					CACHE_UNIT.second, new FarmSuperCatchFunc() {
						public Object function() {
							return DocTypeController.this.farmDocTypeManagerImpl
									.getPopTypesForReadDoc(DocTypeController.this.getCurrentUser(session));
						}
					});
			List<FarmDoctype> typepath = this.farmDocTypeManagerImpl.getTypeAllParent(typeid);
			return ViewMode.getInstance().putAttr("types", types).putAttr("typepath", typepath).returnObjMode();
		} catch (Exception var6) {
			var6.printStackTrace();
			return ViewMode.getInstance().returnObjMode();
		}
	}

	@RequestMapping({ "/PubLoadFqaRType" })
	@ResponseBody
	public Map<String, Object> fqaTypeRead(String typeid, final HttpSession session) {
		try {
			String userid = this.getCurrentUser(session) == null ? "" : this.getCurrentUser(session).getId();
			List<TypeBrief> types = (List) FarmSuperCache.getValue("typeFqaRs" + userid, Integer
					.valueOf(FarmParameterService.getInstance().getParameter("config.wcp.cache.alltypes")).intValue(),
					CACHE_UNIT.second, new FarmSuperCatchFunc() {
						public Object function() {
							return DocTypeController.this.farmDocTypeManagerImpl
									.getPopFqaTypesForReadDoc(DocTypeController.this.getCurrentUser(session));
						}
					});
			List<FarmDoctype> typepath = this.farmDocTypeManagerImpl.getTypeAllParent(typeid);
			return ViewMode.getInstance().putAttr("types", types).putAttr("typepath", typepath).returnObjMode();
		} catch (Exception var6) {
			var6.printStackTrace();
			return ViewMode.getInstance().returnObjMode();
		}
	}

	@RequestMapping({ "/PubLoadWType" })
	@ResponseBody
	public Map<String, Object> typeWrite(String typeid, final HttpSession session) {
		try {
			String userid = this.getCurrentUser(session) == null ? "" : this.getCurrentUser(session).getId();
			List<TypeBrief> types = (List) FarmSuperCache.getValue("typeWs" + userid, Integer
					.valueOf(FarmParameterService.getInstance().getParameter("config.wcp.cache.alltypes")).intValue(),
					CACHE_UNIT.second, new FarmSuperCatchFunc() {
						public Object function() {
							return DocTypeController.this.farmDocTypeManagerImpl
									.getTypesForWriteDoc(DocTypeController.this.getCurrentUser(session));
						}
					});
			List<FarmDoctype> typepath = this.farmDocTypeManagerImpl.getTypeAllParent(typeid);
			return ViewMode.getInstance().putAttr("types", types).putAttr("typepath", typepath).returnObjMode();
		} catch (Exception var6) {
			var6.printStackTrace();
			return ViewMode.getInstance().returnObjMode();
		}
	}

	@RequestMapping({ "/PubLoadFqaWType" })
	@ResponseBody
	public Map<String, Object> typeFqaWrite(String typeid, final HttpSession session) {
		try {
			String userid = this.getCurrentUser(session) == null ? "" : this.getCurrentUser(session).getId();
			List<TypeBrief> types = (List) FarmSuperCache.getValue("typeFqaWs" + userid, Integer
					.valueOf(FarmParameterService.getInstance().getParameter("config.wcp.cache.alltypes")).intValue(),
					CACHE_UNIT.second, new FarmSuperCatchFunc() {
						public Object function() {
							return DocTypeController.this.farmDocTypeManagerImpl
									.getFqaTypesForWriteDoc(DocTypeController.this.getCurrentUser(session));
						}
					});
			List<FarmDoctype> typepath = this.farmDocTypeManagerImpl.getTypeAllParent(typeid);
			return ViewMode.getInstance().putAttr("types", types).putAttr("typepath", typepath).returnObjMode();
		} catch (Exception var6) {
			var6.printStackTrace();
			return ViewMode.getInstance().returnObjMode();
		}
	}
}
